
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;

public class Database {
    // 数据库连接地址
    private static final String URL = "jdbc:mysql://localhost:3306/testdb?useSSL=false";
    // 数据库账号
    private static final String USER = "root";
    // 数据库密码
    private static final String PASSWORD = "111222";
    // 数据库连接
    private Connection connection;
    // 数据库控制器
    private Statement statement;

    public Database() throws Exception {
        // 载入数据库驱动
        Class.forName("com.mysql.jdbc.Driver");
        // 创建数据库连接
        this.setConnection(DriverManager.getConnection(URL, USER, PASSWORD));
        // 创建数据库控制器
        this.setStatement(this.getConnection().createStatement());
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setStatement(Statement statement) {
        this.statement = statement;
    }

    public Statement getStatement() {
        return statement;
    }
}
